<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        ul,
        ol {
            list-style: none;
        }

        img {
            display: block;
        }

        #sports-header {
            width: 100%;
            height: 50px;
            background: #537bff;
            display: flex;
            justify-content: space-between;
            align-items: center;
            color: white;
            font-size: 20px;
            padding: 0 10px;
            /* position: fixed; */
            position: relative;
            top: 0;
            z-index: 100;
        }

        #sports-main {
            margin-top: 50px;
            height: calc(100vh - 50px);
        }

        #sports-main ul {
            background: white;
        }

        #sports-main ul li {
            display: flex;
            border-bottom: 1px #f7f7f7 solid;
            margin: 0 18px;
            padding: 20px 0;
        }

        #sports-main .sports-list-text {
            flex: 1;
            font-size: 18px;
            line-height: 26px;
        }

        #sports-main .sports-list-text p:last-of-type {
            font-size: 14px;
            color: #828c9b;
            display: flex;
            margin-top: 10px;
        }

        #sports-main .sports-list-text p:last-of-type span {
            margin-right: 10px;
        }

        #sports-main .sports-list-img {
            width: 130px;
            margin-left: 20px;
        }

        #sports-main .sports-list-img img {
            width: 100%;
            border-radius: 10px;
        }

        #loadingDown {
            width: 100%;
            position: absolute;
            top: 60px;
            z-index: -1;
            text-align: center;
        }

        #loadingUp {
            width: 100%;
            text-align: center;
            padding: 20px 0;
        }

        #loading {
            position: absolute;
            left: 0;
            top: 0;
            right: 0;
            bottom: 0;
            margin: auto;
            width: 200px;
            height: 30px;
            line-height: 30px;
            text-align: center;
            z-index: 100;
        }
    </style>
    <script src="javascripts/template-web.js"></script>
    <script src="javascripts/axios.js"></script>
    <script src="javascripts/better-scroll.js"></script>
</head>

<body>
    <header id="sports-header">
        腾讯 | 体育
    </header>
    <div id="loadingDown"></div>


    <div>
        <table border="1">
            <thead>
                <tr>
                    <th>姓名</th>
                    <th>年龄</th>
                    <th>性别</th>
                </tr>

            <tbody>


            </tbody>
            </thead>
        </table>
    </div>




    <script>

        /*
        
        动态生成 table , 通过js  document  创建 table 

        
        */ 

        var xhr = new XMLHttpRequest();

        // 发送请求
        xhr.open('GET', '/list', true);
        xhr.send();

        var tbody = document.querySelector('tbody');
        xhr.onload = function () {
            console.log('请求已经完成');
            if (xhr.status === 200) {
                // 获取文本数据
                // console.log("text:",xhr.responseText)

                data = JSON.parse(xhr.responseText);
                // console.log(data);

                for (var i = 0; i < data.list.length; i++) {
                    var tr = document.createElement('tr');
                    // console.log('tr:',tr);
                    for (var attr in data.list[i]) {
                        var td = document.createElement('td');
                        td.innerHTML = data.list[i][attr];
                        // console.log('tr:',tr);
                        tr.appendChild(td);
                    }
                    tbody.appendChild(tr);
                }
                console.log('done....');
            }

        }


    </script>


</body>

</html>